﻿
namespace RayD.Core 
{
    /// <summary>
    /// Session帮助类
    /// </summary>
    public class SessionHelper
    {
        #region Session操作（自定义Session）
        /// <summary>
        /// 写Session
        /// </summary>
        /// <typeparam name="T">Session键值的类型</typeparam>
        /// <param name="key">Session的键名</param>
        /// <param name="value">Session的键值</param>
        public static void Write<T>(string key, T value)
        {
            if (string.IsNullOrEmpty(key))
                return;
            CustomSession.Session[key] = value;
        }

        /// <summary>
        /// 写Session
        /// </summary>
        /// <param name="key">Session的键名</param>
        /// <param name="value">Session的键值</param>
        public static void Write(string key, string value)
        {
            Write<string>(key, value);
        }

        /// <summary>
        /// 读取Session的值
        /// </summary>
        /// <param name="key">Session的键名</param>        
        public static T Get<T>(string key) where T : class
        {
            if (key.IsEmpty())
                return null;
            return CustomSession.Session[key] as T;
        }

        /// <summary>
        /// 读取Session的值
        /// </summary>
        /// <param name="key">Session的键名</param>        
        public static string Get(string key)
        {
            return Get<string>(key);
        }
        /// <summary>
        /// 删除指定Session
        /// </summary>
        /// <param name="key">Session的键名</param>
        public static void Remove(string key)
        {
            if (key.IsEmpty())
                return;
            CustomSession.Session[key] = null;
            CustomSession.RemoveSessionCookie();
        }

        #endregion
    }
}
